import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * This program uses a hash table to store DNA sequence and sequenceID (using the ACGT alphabet)
 *  location and length data it receives from a FileManager that inserts and removes these sequences 
 *  and sequenceIDs into a binary file for storage.
 *  
 *  The program searches through a command list for insert, remove, search and print commands to execute.
 *  It takes these commands and performs the necessary operations on the Hash File and Binary File.
 *  
 *  Insert: First inserts the sequence and sequenceIDs into the binary file. The FileManager then passes
 *  memory handles called MemBlocks to the HashTable where these handles are stored for access later on.
 *  
 *  Remove: First retrieves the location of the sequence and sequenceID from the HashTable and then removes
 *  them from the binary file.
 *  
 *  Search: Searches for the given SequenceID. If found it gets the Sequence from the binary file and outputs
 *  it.
 *  
 *  Print: Prints both the taken hash slots in the hash table, and the free memory blocks in the binary file.
 *  
 *  
 *  Development Environment:
 *  
 *  Operating System: Windows
 *  IDE: Eclipse
 *
 *  @author Erik Rodriguez and Cory Chase
 *  @version May 9, 2013
 *
 *  // On my honor:
//// - I have not used source code obtained from another student,
// or any other unauthorized source, either modified or
// unmodified.
//
// - All source code and documentation used in my program is
// either my original work, or was derived by me from the
// source code published in the textbook for this course.
//
// - I have not discussed coding details about this project with
// anyone other than my partner (in the case of a joint
// submission), instructor, ACM/UPE tutors or the TAs assigned
// to this course. I understand that I may discuss the concepts
// of this program with other students, and that another student
// may help me debug my program so long as neither of us writes
// anything during the discussion or modifies any computer file
// during the discussion. I have violated neither the spirit nor
// letter of this restriction.
 */
public class Main {

	// ----------------------------------------------------------
	/**
	 * This is our main function that links all of our classes together.
	 * @param args
	 */
	
	public static void main(String[] args) {
		FileManager fileManager; 	//Our FileManager that works on the binary file.
		int tableSize;				//The size of our hash table
		File hashFile;				//The hash file that will be written to by the HashTable class
		File memoryFile;			//File where sequence's and sequenceID's are stored
		HashTable hashTable;		//Our hash table
		CommandParser cmdParser;	//The parser that parses commands from the input file
			
		hashFile = new File(args[1]);
		memoryFile = new File(args[3]);
		File inputFile = new File(args[0]); //The input file that stores all the commands
		
		try {
			tableSize = Integer.parseInt(args[2]);
			fileManager = new FileManager(memoryFile);
			hashTable = new HashTable(tableSize,hashFile,fileManager);
			cmdParser = new CommandParser(inputFile, fileManager, hashTable);
			cmdParser.parseCommands();
		} 
		catch (IOException e2) {
			throw new IllegalStateException("Command Line Should Be: P4 <command-file> <hash-file> <hash-table-size> <memory-file>");
		}
		catch(NumberFormatException nfe){
			throw new IllegalArgumentException("Command Line Should Be: P4 <command-file> <hash-file> <hash-table-size> <memory-file>");
		}
	}

}
